package com.itheima.controller;

import com.itheima.pojo.Adress;
import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/jsonparam")
public class ParamJsonController {
    @RequestMapping("/json1")
    @ResponseBody
    public String json1(@RequestBody List<String> list){
        System.out.println(list);
        return "{'info' : 'Json hellow'}";
    }

    @RequestMapping("/json2")
    @ResponseBody
    public String json2(@RequestBody User user){
        System.out.println(user);
        return "{'info' : 'Json hellow'}";
    }

    @RequestMapping("/json3")
    @ResponseBody
    public String json3(@RequestBody List<User> list){
        System.out.println(list);
        return "{'info' : 'Json hellow'}";
    }

    @RequestMapping("/resp00")
    public String respont(){
        System.out.println("respont");
        return "/html/index.html";
    }

    /**
     *@ResponseBody
     */
    @RequestMapping("/resp1")
    @ResponseBody
    public User response1(){
        System.out.println("response1");
        User user = new User();
        user.setId(1);
        user.setName("张三san");
        user.setAge(30);
        return user;
    }

    @RequestMapping("/resp2")
    @ResponseBody
    public List response2(){
        System.out.println("response2");
        ArrayList<User> list = new ArrayList<>();
        User user = new User();
        user.setId(1);
        user.setName("张三");
        user.setAge(30);
        list.add(user);
        list.add(user);
        list.add(user);
        return list;
    }
}
